package org.learn.java;

public class Gamble {

	public static void main(String[] args) {
		int cash = Integer.parseInt(args[0]); // Initial Amount
		int b = Integer.parseInt(args[1]); // Target Amount
		int n = Integer.parseInt(args[2]); // Number of Trials
		System.out.println("$" + cash + " dollars I have, but I need $" + b
				+ " dollars and in " + n + " trials");
		int bets = 0;
		int win = 0;

		for (int i = 0; i < n; i++) {
 
			int a = cash;
			while (a > 0 && a < b) {
				bets++;
				if (Math.random() < 0.5)
					a++; // win $1
				else
					a--; // Lose $1
			}

			if (a == b)
				win++;
		}

		System.out.println(win + " wins of " + n);
		System.out.println("Win % " + (100.0 * win) / n);
		System.out.println("Avg # bets % " + (1.0 * bets) / n);
	}

}
